<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let students = []
			function init(){
				let xhr = new XMLHttpRequest()//创建核心对象
				xhr.open("GET","stus.xml",false)//创建请求
				xhr.send()//发送请求
				let xmldata = xhr.responseXML//接受数据、解析、显示在页面上
				students = xmldata.querySelectorAll("student")
				document.getElementById("sno").value = students[0].getAttribute("sno")
				document.getElementById("sname").value = students[0].getAttribute("sname")
			}
		</script>
	</head>
	<body onload="init()">
		学号：<input type="text" id="sno">
		<br>
		姓名：<input type="text" id="sname">
		<button type="button">下一个</button>
		<script type="text/javascript">
			let n = 1
			document.querySelector("button").onclick = function(){
				n++
				if(n>students.length){
					n = 1//第n个学生
				}
			document.getElementById("sno").value = students[n-1].getAttribute("sno")
			document.getElementById("sname").value = students[n-1].getAttribute("sname")
			}
		</script>
	</body>
</html>
